<!-- <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>1、⿏标点击⻚⾯出现随机颜⾊的⽂字,出现之后向上淡出。</title>
  <style>
    body {
      text-align: center;
      width: 100px;
      height: 1000px;
    }

    .wrap {
      opacity: 100%;
    }
  </style>
</head>

<body>
  <div id="wrap">
    test text
  </div>
  <script>
    var html = document.querySelector('html')
    var wrap = document.getElementById("wrap")
    // 获取元素
    function getColor() {
      // 封装随机生成颜色的函数作为返回值
      return Math.round(Math.random() * 255);
    }

    function giveColor() {
      var red = getColor();
      var green = getColor();
      var blue = getColor();
      // 获取三个rgb的值
      var color = "rgb(" + red + "," + green + "," + blue + ")";
      // 吧rhb值拼接在一起给变量color
      return color;
      // 返回color
    }
    quotes = ['das', 'dhsajk', 'hj', 'yduias', 'dhjsgak', 'hdjkas', 'dhjksa', 'hjkfsd', 'hjfkds', 'hfjkd'] //创建消息数组
    html.onclick = function () {
      wrap.style.color = giveColor();
      wrap.innerHTML = quotes[Math.floor(Math.random() * quotes.length)]
      var time = 1
      // set = setInterval(function () {
      //   wrap.style.opacity = time
      //   time -= 0.5

      // }, 100)

      // btn1注册点击时间，改变wrap的字体颜色
    }

  </script>
</body>

</html> -->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tian</title>
  <style>
    span {
      /* 让弹出来的文字不被选中，影响操作体验 */
      user-select: none;
      cursor: default;
      font-size: 20px;
      color: blanchedalmond;
      position: absolute;
      transition: 1s;
    }
  </style>
</head>

<body>
  <script>
    // 设置随机出现的文字数组
    var arr = ['次数3']

    function getColor() {
      // 封装随机生成颜色的函数作为返回值
      return Math.round(Math.random() * 255);
    }

    function giveColor() {
      var red = getColor();
      var green = getColor();
      var blue = getColor();
      // 获取三个rgb的值
      var color = "rgb(" + red + "," + green + "," + blue + ")";
      // 吧rhb值拼接在一起给变量color
      return color;
      // 返回color
    }

    document.onclick = function (x) {
      // 创建元素节点对象
      var span = document.createElement("span")
      // 获取当前鼠标的坐标
      span.style.left = x.clientX + "px"
      span.style.top = x.clientY + "px"
      // 让span的值为arr数组内随机的一个值
      // span.innerHTML = arr[Math.floor(Math.random() * arr.length)]
      span.innerHTML = '还记得撒'
      span.style.color = giveColor()
      // 设置span的动画效果
      setTimeout(function () {
        span.style.transform = "translateY(-100px)"
        span.style.opacity = "0"

      }, 100)
      // 将span添加到body里
      document.body.appendChild(span)

    }
  </script>
</body>

</html>